package sctu.edu.java.year2016.team03.maoyuhao.day20160521.chapter4_3;

/**
 * 使用while循环求1+1/2!+1/3!...1/20!的和
 * Created by cc on 2016/5/21.
 */
public class Work {
        public static void main(String[] args) {
            double sum = 0d;
            int i = 1;
            while (i <= 20) {
                sum += 1/(double)sum1(i);
                i++;
            }
            System.out.println(sum);
        }

        public static int sum1(int  n) {
            if (n == 1)
                return 1;
            else
                return sum1(n-1)*n ;
        }
    }
